package initialize

import (
	"fmt"
	"github.com/smash-llj/Nexa-server/global"
	"github.com/spf13/viper"
	"github.com/tencentyun/cos-go-sdk-v5"
	"net/http"
	"net/url"
)

func InitUploadClient() *cos.Client {
	bucketName := viper.GetString("UploadBucket.BucketName")
	region := viper.GetString("UploadBucket.Region")
	u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucketName, region))
	b := &cos.BaseURL{BucketURL: u}
	global.UploadClient = cos.NewClient(b, &http.Client{
		Transport: &cos.AuthorizationTransport{
			SecretID:  viper.GetString("UploadBucket.SecretId"),
			SecretKey: viper.GetString("UploadBucket.SecretKey"),
		},
	})
	return global.UploadClient
}
